/*
 * Albareth - an action roleplaying game.
 * Copyright (C) 2008 Jens Anuth
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 *  02110-1301, USA.
 * 
 * $Id: Potion.java 48 2008-05-17 02:04:48Z jens464 $
*/
package albareth.core.entity.item;

import albareth.core.action.Action;
import albareth.core.action.Spell;
import albareth.core.entity.ActionItem;
import albareth.core.entity.Mobile;
import albareth.frontend.Resources;
import albareth.frontend.Tile;

public class Potion extends ActionItem implements Cloneable
{

    public Potion(Tile tile, Spell spell)
    {
        super(spell.getName() + " Potion", tile, spell);
        spell.setCooldownGroup(Mobile.COOLDOWN_GROUP_POTIONS);
        spell.setManaRequirement(0);
        spell.setCastingDuration(0);
        setStackable(true);
    }
    
    public Object clone() throws CloneNotSupportedException
    {
        return super.clone(); 
    }
    
    public boolean onActivate(Mobile src)
    {
        Action action = getAction();
        if (src.tryAction(action)) {
            src.eventMsg("You quaff the potion.");
            src.emitSound(Resources.SOUND_DRINKING);
            consume();
            return true;
        }
        return false;

    }

    public void enchant(int level)
    {
        // TODO Auto-generated method stub
    }
    
    public boolean isStackableWith(Object other)
    {
        if (!(other instanceof Potion)) {
            return false;
        };
        
        Potion otherPotion = (Potion)other;

        if (otherPotion.getTile() != getTile()) {
            return false;
        }
        
        Spell mySpell = (Spell)getAction();
        Spell otherSpell = (Spell)otherPotion.getAction();
        
        if (mySpell.getName().equals(otherSpell.getName()) &&
            mySpell.getSpellStrength() == otherSpell.getSpellStrength())
        {
            return true;
        }
        
        return false;
        
    }


}
